import { createFunctionHandler } from "@roasmax/rabbitmq";
import RedisToolkit from "@roasmax/redis";

// Create a task handler
export const createOnWeiboLoginSuccess = (redis: RedisToolkit) => createFunctionHandler(async (taskData: any) => {
  console.log('Received task:', taskData);
  try {
    const key = `weibo_login:${taskData.userInfo.uid}`;
    await redis.cache.set(key, taskData, { ttl: 3600 }); // Save to Redis with 1-hour expiration
    console.log(`Task data saved to Redis with key: ${key}`);
    return { processed: true };
  } catch (error) {
    console.error('Error saving to Redis:', error);
    const message = error instanceof Error ? error.message : String(error);
    return { processed: false, error: message };
  }
});

